import { defineStore } from 'pinia'
import { store } from '@/store'

const useAppStore = defineStore('app', {
  state: () => {
    return {
      lang: localStorage.getItem('lang') || 'zh_CN',
      loading: false,
    }
  },
  actions: {
    SET_LOCALE (lang) {
      // 判断变量是否存在
      this.locale = lang || 'zh_CN'
      // 存储在本地
      localStorage.setItem('lang', this.locale)
    },
    startLoading( value ) {
      this.loading =value
    },
  }
})

export function useAppStoreHook () {
  return useAppStore(store)
}
